package com.mg.game.content.tasksscreen;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;

import com.mg.framework.kernel.Actor;
import com.mg.framework.kernel.GameApplication;
import com.mg.framework.kernel.Screen;
import com.mg.framework.kernel.Touchable;
import com.mg.game.content.ConstantString;
import com.mg.game.content.TankGame;

public class Task extends Actor implements Touchable {

	private int id;
	private String taskName;
	private TaskManager taskManager;
	private Paint paint;

	public Task(TaskManager taskManager, Screen screen, Bitmap bitmap, int id,
			int width, int height, int widthSpace, int heightSpace) {
		super(screen, bitmap);
		this.id = id;
		this.taskName = ConstantString.LEVEL + id;
		this.taskManager = taskManager;
		this.setWidthAndHeight(width, height);
		this.setX(widthSpace + ((id % 5) * (widthSpace + this.width)));
		this.setY(heightSpace + ((id / 5) * (heightSpace + this.height))
				- ((id / 15) * 3 * (heightSpace + this.height)));
		this.paint = new Paint();
		this.paint.setColor(Color.WHITE);
		this.paint.setTextSize(this.height / 2);
	}

	@Override
	public void gameUpdate() {

	}

	@Override
	public void screenUpdate(Canvas canvas) {
		this.canvas.drawText(String.valueOf((this.id + 1)), this.width / 5, this.height / 4 * 3, this.paint);
		this.drawSelf(canvas, null);
	}

	@Override
	public void onTouchEvent(MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			((TankGame)GameApplication.me).toGameScreen(this.id);
			break;
		}
	}

	@Override
	public boolean isTouched(MotionEvent event) {
		return this.defaultIsTouched(event);
	}
}
